﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    UserModel user = this.ViewData["user"] as UserModel;
}

<!--

    用户Id:_____________
    姓名:_______________
    性别:_______________
    年龄:_______________
         保存   取消

-->

<table class="tz_table tz_w100">
    <tbody>
        <tr>
            <th>用户Id</th>
            <td>
                <input type="text" class="tz_w100" id="txt_id" readonly="readonly" value="@(user.Id)" />
            </td>
        </tr>
        <tr>
            <th>姓名</th>
            <td>
                <input type="text" class="tz_w100" id="txt_name" value="@(user.Name)" />
            </td>
        </tr>
        <tr>
            <th>性别</th>
            <td>
                <input type="text" class="tz_w100" id="txt_gender" value="@(user.Gender)" />
            </td>
        </tr>
        <tr>
            <th>年龄</th>
            <td>
                <input type="text" class="tz_w100" id="txt_age" value="@(user.Age)" />
            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="2">
                <button id="btn_save">保存</button>
                <button id="btn_cancel">取消</button>
            </td>
        </tr>
    </tfoot>
</table>

<script>

    $("#btn_save").click(function () {
        var id = $("#txt_id").val();
        var name = $("#txt_name").val();
        var gender = $("#txt_gender").val();
        var age = $("#txt_age").val();

        var json = {
            id: id,
            name: name,
            gender: gender,
            age: age
        };

        $.ajax({
            url: "/home/doedit",
            data: JSON.stringify(json),
            type: "POST",
            dataType: "JSON",
            contentType: "application/json; charset=utf-8",
            success: function (d) {
                alert(d.message);
                window.location.href = "/";
            },
            error: function (err) {

            }
        });
    });

    $("#btn_cancel").click(function () {
        window.location.href = "/";
    });
</script>